package repository

import (
	"gitee.com/ling1314/origin-utility/db"
	"gitee.com/ling1314/origin-utility/model"
)

type roleRepository struct{}

func (r roleRepository) SelectRolesByUserId(userId int64) (li []model.Role, err error) {
	err = db.GetDB().Raw("select * from sys_role where role_id in ( "+
		" select role_id from sys_map_user_role where user_id =? )", userId).Scan(&li).Error
	return
}

func (r roleRepository) FindAll(isOpen int) (li []*model.Role, err error) {
	err = db.GetDB().Where("is_open =?", isOpen).Find(&li).Error
	return
}
